unit linePrinter;

interface

uses
  Windows, WinSpool, Dialogs, SysUtils, StrUtils;

procedure PrintLogin(Name:string;RFID:string;lgTime:TDateTime);
procedure PrintLogOut(Name:string;RFID:string;lgTime:TDateTime);
procedure PrintIssue(Name:string;RFID:string;Punnet:string;Balance:Integer;lgTime:TDateTime);

implementation

procedure WriteRawStringToPrinter(PrinterName:String; S:String);
var
  Handle: THandle;
  N: DWORD;
  DocInfo1: TDocInfo1;
begin
  if not OpenPrinter(PChar(PrinterName), Handle, nil) then
  begin
    ShowMessage('error ' + IntToStr(GetLastError));
    Exit;
  end;
  with DocInfo1 do begin
    pDocName := PChar('pkhs');
    pOutputFile := nil;
    pDataType := 'RAW';
  end;
  StartDocPrinter(Handle, 1, @DocInfo1);
  StartPagePrinter(Handle);
  WritePrinter(Handle, PChar(S), Length(S), N);
  EndPagePrinter(Handle);
  EndDocPrinter(Handle);
  ClosePrinter(Handle);
end;

procedure PrintLogin(Name:string;RFID:string;lgTime:TDateTime);
var
  s:string;
  stmp:string;
begin
  if Length(RFID)>8 then stmp:='*'+RightStr(RFID,7);
  s:=#27#64;
  s:=s+#27#77#0;
  s:=s+#27#69#0;
  s:='Time related operations(Login):'+#10;
  s:=s+Format('%-10s%-9s%-6s%-4s',['Name','RFID','Time','Date'])+#10;
  s:=s+Format('%-10s%-9s%-6s%-6s',[Name,stmp,formatDateTime('hh:mm',lgTime),
                                        formatDateTime('mm/dd',lgTime)])+#10;
  s:=s+#27#100#3;
  s:=s+#29#86#49;
  WriteRawStringToPrinter(PRINTNAME,s);
end;

procedure PrintLogOut(Name:string;RFID:string;lgTime:TDateTime);
var
  s:string;
  stmp:string;
begin
  if Length(RFID)>8 then stmp:='*'+RightStr(RFID,7);
  s:=#27#64;
  s:=s+#27#77#0;
  s:=s+#27#69#0;
  s:='Time related operations(LogOut):'+#10;
  s:=s+Format('%-10s%-9s%-6s%-4s',['Name','RFID','Time','Date'])+#10;
  s:=s+Format('%-10s%-9s%-6s%-6s',[Name,stmp,formatDateTime('hh:mm',lgTime),
                                        formatDateTime('mm/dd',lgTime)])+#10;
  s:=s+#27#100#3;
  s:=s+#29#86#49;
  WriteRawStringToPrinter(PRINTNAME,s);
end;

procedure PrintIssue(Name:string;RFID:string;Punnet:string;Balance:Integer;lgTime:TDateTime);
var
  s:string;
  stmp:string;
begin
  if Length(RFID)>8 then stmp:='*'+RightStr(RFID,7);
  s:=#27#64;
  s:=s+#27#77#0;
  s:=s+#27#69#0;
  s:='Punnet related opertions:'+#10;
  s:=s+Format('....Name:    %s',[Name])+#10;
  s:=s+Format('....RFID:    %s',[stmp])+#10;
  s:=s+Format('....Punnet:  %s',[Punnet])+#10;
  s:=s+Format('....Balance: %dpcs',[Balance])+#10;
  s:=s+'....Time:    '+FormatDateTime('mm-dd',lgTime)+#10;
  s:=s+#27#100#3;
  s:=s+#29#86#49;
  WriteRawStringToPrinter(PRINTNAME,s);
end;

end.
